home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / fadescreen.c < prev    next >
C/C++ Source or Header  |  1994-11-25  |  4KB  |  190 lines

  1. ; /*
  2. sc fadescreen.c DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 STRUCTUREEQUIVALENCE NOSTDIO
  3. slink from lib:c.o fadescreen.o to //Clients/FadeScreen lib /lib/client.lib lib:sc.lib lib:amiga.lib SC SD STRIPDEBUG NOICONS
  4. delete fadescreen.o
  5. quit
  6.  
  7.  FadeScreen 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/memory.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/intuitionbase.h>
  16. #include <graphics/gfxbase.h>
  17.  
  18. #include <clib/exec_protos.h>
  19. #include <clib/graphics_protos.h>
  20.  
  21. #include "/include/client.h"
  22.  
  23. struct IntuitionBase *IntuitionBase;
  24. struct GfxBase *GfxBase;
  25. struct Library *BitMapBase;
  26.  
  27. struct Screen *scr;
  28. UWORD scrdepth;
  29.  
  30. struct DisplayIDInformation *dinfo;
  31. ULONG command;
  32.  
  33.  
  34. BOOL CheckAA( void )
  35. {
  36. if ( GfxBase->ChipRevBits0 & 1<<GFXB_AA_ALICE )
  37.     return ( TRUE );
  38. else
  39.     return( FALSE );
  40. }
  41.  
  42.  
  43. void FadeOut( void )
  44. {
  45. UWORD n;
  46. ULONG color;
  47. BOOL still_fading, blanking;
  48. ULONG *current, *colors, *faded, colorsize = (257 * 3 + 1) * sizeof(ULONG);
  49. ULONG r, g, b;
  50. BOOL result = FALSE;
  51.  
  52. scr = IntuitionBase->FirstScreen;
  53. scrdepth = scr->RastPort.BitMap->Depth;
  54.  
  55. if ( colors = AllocVec( colorsize, MEMF_ANY|MEMF_CLEAR ) )
  56.     {
  57.     if ( faded = AllocVec( colorsize, MEMF_ANY|MEMF_CLEAR ) )
  58.         {
  59.         if ( CheckAA() )
  60.             {
  61.             current = colors;
  62.             current++;
  63.             GetRGB32( scr->ViewPort.ColorMap, 0, 1<<scrdepth, current );
  64.             *colors = (1L<<scrdepth)<<16;
  65.             CopyMem( colors, faded, colorsize );
  66.             }
  67.         else
  68.             {
  69.             current = colors;
  70.             current++;
  71.             for ( n = 0; n < 1<<scrdepth; n++ )
  72.                 {
  73.                 color = GetRGB4( scr->ViewPort.ColorMap, n );
  74.                 *current++ = color >> 8;
  75.                 *current++ = (color & 0xF0) >> 4;
  76.                 *current++ = color & 0xF;
  77.                 CopyMem( colors, faded, colorsize );
  78.                 }
  79.             }
  80.  
  81.         result = TRUE;
  82.         SpritesOff();
  83.  
  84.         blanking = TRUE;
  85.         still_fading = TRUE;
  86.  
  87.         while( blanking )
  88.             {
  89.             if ( still_fading )
  90.                 command = GetServerCommand();
  91.             else
  92.                 command = WaitServerCommand();
  93.  
  94.             if ( command == COMMAND_QUIT )
  95.                 blanking = FALSE;
  96.             else
  97.             if ( still_fading )
  98.                 {
  99.                 current = faded;
  100.                 current++;
  101.  
  102.                 still_fading = FALSE;
  103.                 if ( CheckAA() )
  104.                     {
  105.                     for ( n = 0; n < 1<<scrdepth; n++ )
  106.                         {
  107.                         if ( *current >> 24 )
  108.                             *current -= 0x01000000;
  109.                         r = *current++;
  110.                         if ( *current >> 24 )
  111.                             *current -= 0x01000000;
  112.                         g = *current++;
  113.                         if ( *current >> 24 )
  114.                             *current -= 0x01000000;
  115.                         b = *current++;
  116.  
  117.                         if ( (r|g|b) >> 24 )
  118.                             still_fading = TRUE;
  119.                         }
  120.  
  121.                     WaitTOF();
  122.                     LoadRGB32( &scr->ViewPort, faded );
  123.                     }
  124.                 else
  125.                     {
  126.                     WaitTOF();
  127.                     for ( n = 0; n < 1<<scrdepth; n++ )
  128.                         {
  129.                         if ( *current )
  130.                             *current -= 0x01;
  131.                         r = *current++;
  132.                         if ( *current )
  133.                             *current -= 0x01;
  134.                         g = *current++;
  135.                         if ( *current )
  136.                             *current -= 0x01;
  137.                         b = *current++;
  138.  
  139.                         if ( r|g|b )
  140.                             still_fading = TRUE;
  141.  
  142.                         SetRGB4( &scr->ViewPort, n, r, g, b );
  143.                         }
  144.                     }
  145.                 }
  146.             }
  147.  
  148.         SpritesOn();
  149.  
  150.         current = colors;
  151.         current++;
  152.  
  153.         if ( CheckAA() )
  154.             LoadRGB32( &scr->ViewPort, colors );
  155.         else
  156.             for ( n = 0; n < 1<<scrdepth; n++ )
  157.                 {
  158.                 r = *current++;
  159.                 g = *current++;
  160.                 b = *current++;
  161.                 SetRGB4( &scr->ViewPort, n, r, g, b );
  162.                 }
  163.  
  164.         FreeVec( faded );
  165.         }
  166.     FreeVec( colors );
  167.     }
  168.  
  169. if ( !result )
  170.     SendClientMsg( ACTION_FAILED );
  171. }
  172.  
  173.  
  174. void __main( char *line )
  175. {
  176. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 36L ) )
  177.     {
  178.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library",0L ) )
  179.         {
  180.         if ( dinfo = OpenCommunication() )
  181.             {
  182.             FadeOut();
  183.             CloseCommunication( dinfo );
  184.             }
  185.         CloseLibrary( (struct Library *)GfxBase );
  186.         }
  187.     CloseLibrary( (struct Library *)IntuitionBase );
  188.     }
  189. }
  190.